class ActivityInviteUI extends UIBase{
    private btn_oneKey:BaseButton;
    private item_1:InviteItemUI;
    private item_2:InviteItemUI;
    private item_3:InviteItemUI;
    private item_4:InviteItemUI;
    private item_5:InviteItemUI;
    private btn_back:BaseButton;
    
    constructor()
    {
        super('ActivityInviteView',{showBG:true});
    }

    public init()
    {
        super.init(true);
        this.requestInfo();
    }

    public requestInfo()
    {
        let data = {
            version:GameConst.version
        }
		HttpManager.instance().sendPost(GameConst.httpUrl + 'warriorother/get_invite_info', StringUtil.jsonToHttpPostString(data), (e)=>{
            let data = JSON.parse(e)
            if(data && data.data)
			{
				this.initUI(data.data);
			}
        }, this);
    }

    public initUI(data)
    {
        this.data = data;
        let num = data.invite_list.length;
        let isGet = data.is_get;
        let inviteList = data.invite_list;
        if(num >= 5)
        {
            this.btn_oneKey.visible = true;
        }
        if(isGet)
        {
            let img:eui.Image = this.btn_oneKey.getChildByName('okImg') as eui.Image;
            if(img)
            {
                ShaderUtil.ImgGray(img);
            }
        }
        let award:string = this.data.award;
        let awardArr = award.split(',');
        awardArr.forEach((value, i, arr)=>{
            let index = i + 1;
            let info = value;
            let role_info = inviteList[i];
            let detil = {
                item_info:info,
                role_info:role_info
            }
            let inviteItemUI:InviteItemUI = this['item_'+index];
            inviteItemUI.initUI(detil);
        })
    }

    protected updateUI()
    {
        this.data.is_get = true;
        let img:eui.Image = this.btn_oneKey.getChildByName('okImg') as eui.Image;
        if(img)
        {
            ShaderUtil.ImgGray(img);
        }
        RoleCache.instance().inviteRedPoint = true;
        GameUtil.updateRedPoint(RedPointID.invite);
        // let award = this.data.award;
        // GameUtil.openAwardUI(award, null, null);
    }

    public addEvent()
    {
        this.btn_oneKey.addTapHandler(this.getAwardHandle,this);
        this.btn_back.addTapHandler(this.back, this);
    }

    public back()
    {
        this.remove(3);
    }

    protected getAwardHandle()
    {
        let num = this.data.invite_list.length;
        let isGet = this.data.is_get;
        if(num < 5)
        {
            MessageUtil.tips('还没有达到满足条件哦！');
            return;
        }
        if(isGet)
        {
            MessageUtil.tips('已经领取过了哦!');
            return;
        }
        if(num >= 5 && !isGet) 
        {
            let parma = {
                type:'invite_award'
            }
            ActivityPrase.instance().getWelfare(parma, this.updateUI, this);
        }
    }

    public removeEvent()
    {
        this.btn_oneKey.removeTapHandler();
        this.btn_back.removeTapHandler();
    }   

    public clear()
    {
        super.clear();
    }
}